'''
Created on 17.7.2011

@author: gilead
'''
from direct.actor.Actor import Actor

class Ship(Actor):
    '''
    classdocs
    '''
    def __init__(self, model, guid, ownerid):
        '''
        Constructor
        '''
        Actor.__init__(self, model)
        self.setPythonTag('Ship', self) # HUOM: objekti ei havia muistista ennen kuin tama tag poistetaan
        
        self.guid = guid
        self.ownerid = ownerid
        self.movementTarget = None
        
        self.velocity = 0
        
        self.plannedHeading = None
        self.plannedVelocity = None
        
        # kokoa tulostellaan kun model muuttuu, ja java-puolta tarvitsee paivittaa
        #self.printSize()
    
    def printSize(self):
        min,max = self.getTightBounds()
        size = max - min
        print "minX minY maxX maxY:",min.getX(),min.getY(), max.getX(), max.getY() 
        print "size:",size.getX(),",",size.getY()
    
    def setReadyForDeletion(self):
        self.clearPythonTag('Ship')
     
    def setMovementTarget(self, pos):
        self.movementTarget = pos
        self.movementTarget.setZ(0)
        
    def getVelocity(self):
        return self.velocity
    
    def setVelocity(self, vel):
        self.velocity = vel
        
    def getTurret(self, index):
        for shipchild in self.getChildren():
            turret = shipchild.getPythonTag('Turret')
            if turret != None:
                if turret.id == index:
                    return turret # None jos tagia ei loydy, oikeaa tyyppia muuten
        return None